package com.muyu.product.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.product.domain.model.RuleAttrAddModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.experimental.SuperBuilder;
import io.swagger.annotations.*;
import com.muyu.common.core.annotation.Excel;
import com.muyu.product.domain.req.RuleAttrInfoQueryReq;
import com.muyu.product.domain.req.RuleAttrInfoSaveReq;
import com.muyu.product.domain.req.RuleAttrInfoEditReq;
import com.muyu.common.core.web.domain.BaseEntity;

import java.util.Date;
import java.util.function.Supplier;

/**
 * 规格详情对象 rule_attr_info
 *
 * @author DongZeLiang
 * @date 2024-02-27
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@TableName("rule_attr_info")
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "RuleAttrInfo", description = "规格详情")
public class RuleAttrInfo extends BaseEntity {

    private static final long serialVersionUID = 1L;

    /** 主键 */
    @TableId(value = "id",type = IdType.AUTO)
    @ApiModelProperty(name = "主键", value = "主键")
    private Long id;

    /** 规格id */
    @Excel(name = "规格id")
    @ApiModelProperty(name = "规格id", value = "规格id", required = true)
    private Long ruleId;

    /** 类目名称 */
    @Excel(name = "类目名称")
    @ApiModelProperty(name = "类目名称", value = "类目名称")
    private String name;

    /** 规格值 */
    @Excel(name = "规格值")
    @ApiModelProperty(name = "规格值", value = "规格值")
    private String attrValue;

    /**
    * 查询构造器
    */
    public static RuleAttrInfo queryBuild( RuleAttrInfoQueryReq ruleAttrInfoQueryReq){
        return RuleAttrInfo.builder()
                .ruleId(ruleAttrInfoQueryReq.getRuleId())
                .name(ruleAttrInfoQueryReq.getName())
                .attrValue(ruleAttrInfoQueryReq.getAttrValue())
                .build();
    }

    /**
    * 添加构造器
    */
    public static RuleAttrInfo saveBuild(RuleAttrInfoSaveReq ruleAttrInfoSaveReq){
        return RuleAttrInfo.builder()
                .ruleId(ruleAttrInfoSaveReq.getRuleId())
                .name(ruleAttrInfoSaveReq.getName())
                .attrValue(ruleAttrInfoSaveReq.getAttrValue())
                .build();
    }

    /**
    * 修改构造器
    */
    public static RuleAttrInfo editBuild(Long id, RuleAttrInfoEditReq ruleAttrInfoEditReq){
        return RuleAttrInfo.builder()
            .id(id)
                .ruleId(ruleAttrInfoEditReq.getRuleId())
                .name(ruleAttrInfoEditReq.getName())
                .attrValue(ruleAttrInfoEditReq.getAttrValue())
                .build();
    }

    public static RuleAttrInfo addModelBuild (RuleAttrAddModel ruleAttrAddModel, Supplier<Long> ruleId, Supplier<String> createBy) {
        return RuleAttrInfo.builder()
                .ruleId(ruleId.get())
                .name(ruleAttrAddModel.getName())
                .attrValue(String.join(",", ruleAttrAddModel.getValueList()))
                .createBy(createBy.get())
                .createTime(new Date())
                .build();
    }
}
